#include <iostream>
#include <cassert>
#include <cstring>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

using namespace std;

int main()
{
    int wfd = open("workFifo", O_WRONLY);
    if(wfd < 0)
    {
        cerr << "打开管道文件失败" << endl;
        return 1;
    }
    string message;
    cout << "可以开始向管道中写数据了" << endl;
    while(true)
    {
        getline(cin, message);
        cout << "本次向管道中写入的数据个数是" << message.size() << endl;
        int s = write(wfd, message.c_str(), message.size());
        if(s < 0)
        {
            cerr << "向管道文件中写入数据失败 " << errno << " " << strerror(errno) << endl;
            break;
        }
    }
    close(wfd);
    return 0;
}